|
RAIS
3.2
|
00001 00027 using System; 00028 using System.Data; 00029 using System.Configuration; 00030 using System.Collections; 00031 using System.Web; 00032 using System.Web.Security; 00033 using System.Web.UI; 00034 using System.Web.UI.WebControls; 00035 using System.Web.UI.WebControls.WebParts; 00036 using System.Web.UI.HtmlControls; 00037 using RAIS.Common.UserManagement; 00038 using FunctionRoleCategories = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole.Category>; 00039 using FunctionRoleSubcategories = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole.Subcategory>; 00040 using Masks = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.Mask>; 00041 using DynamicMasks = System.Collections.Generic.Dictionary<string, RAIS.Common.DynamicMaskManagement.DynamicMask>; 00042 using RAIS.UI.Common; 00043 using RAIS.Common.DynamicMaskManagement; 00044 using Queries = System.Collections.Generic.Dictionary<string, RAIS.Common.TableManagement.Query>; 00045 using System.Text; 00046 using System.Collections.Generic; 00047 using System.IO; 00048 00049 namespace RAIS.UI.SpecificMasks 00050 { 00054 public partial class SpecificReports : System.Web.UI.Page 00055 { 00056 #region ENUMS 00057 private enum FormMode { View, Add, Edit, Delete } 00058 #endregion 00059 00060 #region PROPERTIES 00061 protected UserData CurrentUser 00062 { 00063 get { return (UserData)this.Session[UI.Common.Constants.CURRENT_USER_TAG]; } 00064 } 00065 private RAIS.Common.TableManagement.Query SelectedQuery 00066 { 00067 get 00068 { 00069 Queries queries = RAIS.ApplicationLogicLayer.TableManagement.GetQueriesByCustomizationType(RAIS.Common.TableManagement.Query.CustomizationType.QueryReport); 00070 if (queries != null && queries.ContainsKey(this.DDLquery.SelectedItem.Text)) 00071 return queries[this.DDLquery.SelectedItem.Text]; 00072 else 00073 return null; 00074 } 00075 } 00076 private FunctionRole.Category SelectedCategory 00077 { 00078 get 00079 { 00080 FunctionRoleCategories categories = UI.Common.TableManagement.GetFunctionRoleCategories(this, false); 00081 if (DDLmainMenu.SelectedIndex == 0 && categories != null && categories.ContainsKey("Query")) 00082 return categories["Query"]; 00083 else if (DDLmainMenu.SelectedIndex == 1 && categories != null && categories.ContainsKey("Statistics")) 00084 return categories["Statistics"]; 00085 else 00086 return null; 00087 } 00088 } 00089 private FunctionRole.Subcategory SelectedSubcategory 00090 { 00091 get 00092 { 00093 if (this.SelectedCategory != null) 00094 { 00095 string subcategory = SpecificReportManagement.GetSubcategoryNameByReportID(SelectedSpecificReportID); 00096 FunctionRoleSubcategories subcategories = UI.Common.TableManagement.GetFunctionRoleSubcategoriesByCategory(this, this.SelectedCategory, false, false, false); 00097 if (subcategories != null && subcategories.ContainsKey(subcategory)) 00098 return subcategories[subcategory]; 00099 else 00100 return null; 00101 } 00102 else 00103 return null; 00104 } 00105 } 00106 private Mask SelectedMask 00107 { 00108 get 00109 { 00110 return SpecificReportManagement.GetMaskByReportName(this.LBXreports.SelectedItem.Text); 00111 } 00112 } 00113 private DynamicMask SelectedDynamicMask 00114 { 00115 get 00116 { 00117 if (this.SelectedMask != null) 00118 { 00119 DynamicMasks dynamicMasks = RAIS.ApplicationLogicLayer.DynamicMaskManagement.GetDynamicMasksByMask(this.SelectedMask); 00120 00121 if (dynamicMasks != null && dynamicMasks.ContainsKey(this.LBXreports.SelectedItem.Text)) 00122 { 00123 DynamicMask dynamicMask = dynamicMasks[this.LBXreports.SelectedItem.Text]; 00124 return dynamicMask; 00125 } 00126 else 00127 return null; 00128 } 00129 else 00130 return null; 00131 } 00132 } 00133 private int SelectedSpecificReportID 00134 { 00135 get 00136 { 00137 return int.Parse(LBXreports.SelectedValue); 00138 } 00139 } 00140 private bool GenerateMenuItem 00141 { 00142 get 00143 { 00144 if (DDLyesNo.SelectedIndex == 0) 00145 return true; 00146 else return false; 00147 } 00148 } 00149 private FormMode CurrentFormMode 00150 { 00151 get 00152 { 00153 if (Session["SpecificReportsCurrentFormMode"] != null) 00154 return (FormMode)Session["SpecificReportsCurrentFormMode"]; 00155 else return FormMode.View; 00156 } 00157 set 00158 { 00159 Session["SpecificReportsCurrentFormMode"] = value; 00160 } 00161 } 00162 #endregion 00163 00164 #region EVENTHANDLER 00165 00168 protected void Page_PreLoad(object sender, EventArgs e) 00169 { 00170 RAIS.UI.Common.PageManagement.TrimTextBoxValues(this); 00171 } 00175 protected void Page_Load(object sender, EventArgs e) 00176 { 00177 this.Response.Cache.SetNoStore(); 00178 if (this.CurrentUser == null) 00179 UI.Common.AccessManagement.SignOut(this); 00180 00181 if (!IsPostBack) 00182 { 00183 this.LBLusernameNoTranslation.Text = this.CurrentUser.Name; 00184 UI.Common.PageManagement.InitializePageTreeForCategory(this, this.TreeView1, RAIS.Common.Constants.CATEGORY_NAME_ADMINISTRATION); 00185 this.LBLadmin.ForeColor = RAIS.UI.Common.Constants.COLOR_OF_MENU_BAR_TEXT_HIGHLIGHT; 00186 DDLmainMenu.Items.Add(RAIS.Common.Constants.CATEGORY_NAME_QUERY); 00187 DDLmainMenu.Items.Add(RAIS.Common.Constants.CATEGORY_NAME_STATISTICS); 00188 00189 foreach (KeyValuePair<string, string> pair in SpecificReportManagement.GetReports()) 00190 { 00191 LBXreports.Items.Add(new ListItem(pair.Value, pair.Key)); 00192 } 00193 foreach (KeyValuePair<string, RAIS.Common.TableManagement.Query> pair in RAIS.ApplicationLogicLayer.TableManagement.GetQueriesByCustomizationType(RAIS.Common.TableManagement.Query.CustomizationType.QueryReport)) 00194 { 00195 DDLquery.Items.Add(new ListItem(pair.Value.Name, pair.Value.ID.ToString())); 00196 } 00197 foreach (KeyValuePair<string, string> pair in SpecificReportManagement.GetSubcategories("Query")) 00198 { 00199 DDLsubMenu.Items.Add(new ListItem(pair.Value, pair.Key)); 00200 } 00201 if (LBXreports.Items.Count > 0) 00202 { 00203 LBXreports.SelectedIndex = 0; 00204 LNKfieldMapping.Enabled = true; 00205 if (Session["SelectedSpecificReportID"] != null) 00206 { 00207 ListItem selectedItem = LBXreports.Items.FindByValue(Session["SelectedSpecificReportID"].ToString()); 00208 if (selectedItem != null) 00209 LBXreports.SelectedIndex = LBXreports.Items.IndexOf(selectedItem); 00210 } 00211 else 00212 Session["SelectedSpecificReportID"] = this.SelectedSpecificReportID; 00213 SpecificReportManagement.InitControlsBySpecificReportID(SelectedSpecificReportID, TBXreportName, DDLquery, DDLmainMenu, DDLsubMenu, LNKdownload, DDLyesNo); 00214 } 00215 else 00216 { 00217 BTNedit.Enabled = false; 00218 BTNdelete.Enabled = false; 00219 } 00220 00221 DDLyesNo.Items.Add(RAIS.ApplicationLogicLayer.Localisation.Translate("Yes", "ASP.specificreports_aspx", RAIS.Common.Constants.DEFAULT_LANGUAGE, this.CurrentUser.Language)); 00222 DDLyesNo.Items.Add(RAIS.ApplicationLogicLayer.Localisation.Translate("No", "ASP.specificreports_aspx", RAIS.Common.Constants.DEFAULT_LANGUAGE, this.CurrentUser.Language)); 00223 } 00224 00225 UI.Common.Localisation.TranslatePage(this); 00226 UI.Common.PageManagement.InitHelpMainMenu(LBTNdefault); 00227 } 00231 protected void Page_Init(object sender, EventArgs e) 00232 { 00233 PageManagement.SetScrolableListBox(this.LBXreports, this, true); 00234 } 00238 protected void LBXreports_SelectedIndexChanged(object sender, EventArgs e) 00239 { 00240 if (LBXreports.SelectedItem != null) 00241 { 00242 SpecificReportManagement.InitControlsBySpecificReportID(SelectedSpecificReportID, TBXreportName, DDLquery, DDLmainMenu, DDLsubMenu, LNKdownload, DDLyesNo); 00243 BTNedit.Enabled = true; 00244 BTNdelete.Enabled = true; 00245 LNKfieldMapping.Enabled = true; 00246 Session["SelectedSpecificReportID"] = SelectedSpecificReportID; 00247 } 00248 else 00249 { 00250 LNKfieldMapping.Enabled = false; 00251 } 00252 } 00256 protected void LNKfieldMapping_Click(object sender, EventArgs e) 00257 { 00258 this.Response.Redirect("~/SpecificReportFieldMapping.aspx"); 00259 } 00263 protected void BTNadd_Click(object sender, EventArgs e) 00264 { 00265 SetFormMode(FormMode.Add); 00266 } 00270 protected void BTNapply_Click(object sender, EventArgs e) 00271 { 00272 if (TBXreportName.Text != String.Empty && (UPLreportFile.HasFile || LBXreports.SelectedItem != null)) 00273 { 00274 string returnMessage = String.Empty; 00275 bool success = RAIS.ApplicationLogicLayer.TableManagement.CreateQuery(this.SelectedQuery, ref returnMessage); 00276 00277 if (success) 00278 { 00279 try 00280 { 00281 if (LBXreports.Items.FindByText(TBXreportName.Text) == null || (LBXreports.SelectedItem != null && TBXreportName.Text.Equals(LBXreports.SelectedItem.Text))) 00282 { 00283 string fileName = Path.GetFileName(UPLreportFile.PostedFile.FileName); 00284 bool addEditSuccess = false; 00285 if (this.CurrentFormMode == FormMode.Add) 00286 { 00287 // Add mask/dynamic mask 00288 DynamicMask dynamicMask = new DynamicMask(); 00289 dynamicMask.Name = TBXreportName.Text; 00290 dynamicMask.Type = RAIS.Common.DynamicMaskManagement.DynamicMask.DynamicMaskType.ReportMask; 00291 dynamicMask.SetNewQuery(this.SelectedQuery); 00292 success = RAIS.ApplicationLogicLayer.DynamicMaskManagement.AddDynamicMask( 00293 int.Parse(this.DDLsubMenu.SelectedValue) 00294 , this.TBXreportName.Text 00295 , dynamicMask 00296 , ref returnMessage); 00297 00298 if (!success) 00299 { 00300 RAIS.ApplicationLogicLayer.DynamicMaskManagement.RemoveDynamicMask(dynamicMask, ref returnMessage); 00301 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00302 returnMessage, 00303 success); 00304 } 00305 else 00306 { 00307 // Add specific report 00308 System.IO.Stream stream = UPLreportFile.PostedFile.InputStream; 00309 int length = UPLreportFile.PostedFile.ContentLength; 00310 byte[] data = new byte[length]; 00311 stream.Read(data, 0, length); 00312 string reportDefinition = System.Text.UTF8Encoding.UTF8.GetString(data); 00313 if (reportDefinition.IndexOf("<?xml") >= 0) 00314 reportDefinition = reportDefinition.Substring(reportDefinition.IndexOf("<?xml")); 00315 int reportID = 0; 00316 success = SpecificReportManagement.AddSpecificReport(TBXreportName.Text, fileName, reportDefinition, ref reportID); 00317 00318 if (reportDefinition.StartsWith("<?xml") && success) 00319 { 00320 addEditSuccess = true; 00321 00322 // Generate menu item 00323 SpecificReportManagement.GenerateMenuItem(reportID, this.GenerateMenuItem); 00324 } 00325 else 00326 { 00327 SpecificReportManagement.RemoveSpecificReport(reportID, ref returnMessage); 00328 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00329 "Error occured concerning the uploaded file!", 00330 false); 00331 } 00332 } 00333 } 00334 else 00335 { 00336 // Edit existing specific report 00337 if (UPLreportFile.HasFile) 00338 { 00339 Stream stream = UPLreportFile.PostedFile.InputStream; 00340 int length = UPLreportFile.PostedFile.ContentLength; 00341 byte[] data = new byte[length]; 00342 stream.Read(data, 0, length); 00343 string reportDefinition = System.Text.UTF8Encoding.UTF8.GetString(data); 00344 if (reportDefinition.IndexOf("<?xml") >= 0) 00345 reportDefinition = reportDefinition.Substring(reportDefinition.IndexOf("<?xml")); 00346 if (reportDefinition.StartsWith("<?xml") && SpecificReportManagement.UpdateSpecificReport(SelectedSpecificReportID, this.SelectedMask.ID, this.SelectedDynamicMask.ID, int.Parse(this.DDLsubMenu.SelectedValue), TBXreportName.Text, fileName, reportDefinition)) 00347 { 00348 LBXreports.SelectedItem.Text = TBXreportName.Text; 00349 DynamicMask dynamicMask = this.SelectedDynamicMask; 00350 dynamicMask.SetNewQuery(this.SelectedQuery); 00351 RAIS.ApplicationLogicLayer.DynamicMaskManagement.SaveDynamicMask(dynamicMask, ref returnMessage); 00352 addEditSuccess = true; 00353 } 00354 } 00355 else 00356 { 00357 addEditSuccess = SpecificReportManagement.UpdateSpecificReport(SelectedSpecificReportID, this.SelectedMask.ID, this.SelectedDynamicMask.ID, int.Parse(this.DDLsubMenu.SelectedValue), TBXreportName.Text, null, null); 00358 if (addEditSuccess) 00359 { 00360 LBXreports.SelectedItem.Text = TBXreportName.Text; 00361 DynamicMask dynamicMask = this.SelectedDynamicMask; 00362 dynamicMask.SetNewQuery(this.SelectedQuery); 00363 RAIS.ApplicationLogicLayer.DynamicMaskManagement.SaveDynamicMask(dynamicMask, ref returnMessage); 00364 } 00365 } 00366 // Generate menu item 00367 SpecificReportManagement.GenerateMenuItem(this.SelectedSpecificReportID, this.GenerateMenuItem); 00368 } 00369 00370 if (addEditSuccess) 00371 { 00372 int index = LBXreports.SelectedIndex; 00373 LBXreports.Items.Clear(); 00374 foreach (KeyValuePair<string, string> pair in SpecificReportManagement.GetReports()) 00375 { 00376 LBXreports.Items.Add(new ListItem(pair.Value, pair.Key)); 00377 } 00378 if (index >= 0) 00379 { 00380 LBXreports.SelectedIndex = index; 00381 } 00382 else 00383 LBXreports.SelectedIndex = LBXreports.Items.Count - 1; 00384 Session["SelectedSpecificReportID"] = SelectedSpecificReportID; 00385 SetFormMode(FormMode.View); 00386 } 00387 else 00388 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00389 "Error occured concerning the uploaded file!", 00390 false); 00391 } 00392 else 00393 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00394 "A specific report with this name already exists.", 00395 false); 00396 } 00397 catch (Exception ex) 00398 { 00399 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00400 "An error occured while processing your request!", 00401 false); 00402 LBLresult.Text += " - " + ex.ToString(); 00403 } 00404 } 00405 else 00406 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00407 "Query Error: " + returnMessage, 00408 false); 00409 } 00410 else 00411 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00412 "Please insert the necessary data correctly.", 00413 false); 00414 } 00418 protected void BTNundo_Click(object sender, EventArgs e) 00419 { 00420 SetFormMode(FormMode.View); 00421 } 00425 protected void BTNedit_Click(object sender, EventArgs e) 00426 { 00427 SetFormMode(FormMode.Edit); 00428 } 00432 protected void BTNdelete_Click(object sender, EventArgs e) 00433 { 00434 if (this.LBXreports.SelectedItem != null && !SpecificReportManagement.IsSubreport(this.LBXreports.SelectedItem.Text)) 00435 { 00436 string returnMessage = String.Empty; 00437 bool success = SpecificReportManagement.RemoveSpecificReport(int.Parse(LBXreports.SelectedValue.ToString()), ref returnMessage); 00438 if (!success) 00439 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00440 returnMessage, 00441 success); 00442 else 00443 LBLresult.Text = String.Empty; 00444 LBXreports.Items.Clear(); 00445 foreach (KeyValuePair<string, string> pair in SpecificReportManagement.GetReports()) 00446 { 00447 LBXreports.Items.Add(new ListItem(pair.Value, pair.Key)); 00448 } 00449 SetFormMode(FormMode.Delete); 00450 } 00451 else 00452 { 00453 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00454 "The specific report is currently used as subreport and cannot be deleted at the moment.", 00455 false); 00456 } 00457 } 00461 protected void BTNdownload_Click(object sender, EventArgs e) 00462 { 00463 Response.Clear(); 00464 Response.Buffer = true; 00465 Response.ContentType = "application/octetstream"; 00466 Response.AddHeader("content-disposition", "attachment; filename=" + LNKdownload.Text); 00467 Response.BinaryWrite(SpecificReportManagement.GetSpecificReportFile(SelectedSpecificReportID)); 00468 Response.Flush(); 00469 Response.End(); 00470 } 00476 protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) 00477 { 00478 UI.Common.UserManagement.ProcessTreeViewOnRedirect(this.TreeView1); 00479 } 00485 protected void LBTNlogout_Click(object sender, EventArgs e) 00486 { 00487 UI.Common.AccessManagement.SignOut(this); 00488 } 00492 protected void DDLmainMenu_SelectedIndexChanged(object sender, EventArgs e) 00493 { 00494 DDLsubMenu.Items.Clear(); 00495 foreach (KeyValuePair<string, string> pair in SpecificReportManagement.GetSubcategories(DDLmainMenu.SelectedItem.Text)) 00496 { 00497 DDLsubMenu.Items.Add(new ListItem(pair.Value, pair.Key)); 00498 } 00499 } 00500 #endregion 00501 00502 #region PRIVATE HELPER METHODS 00503 00506 private void SetFormMode(FormMode mode) 00507 { 00508 this.CurrentFormMode = mode; 00509 switch (mode) 00510 { 00511 case FormMode.Add: 00512 LBXreports.Enabled = false; 00513 TBXreportName.Enabled = true; 00514 DDLquery.Enabled = true; 00515 DDLmainMenu.Enabled = true; 00516 DDLsubMenu.Enabled = true; 00517 UPLreportFile.Enabled = true; 00518 BTNadd.Enabled = false; 00519 BTNedit.Enabled = false; 00520 BTNdelete.Enabled = false; 00521 BTNundo.Enabled = true; 00522 BTNapply.Enabled = true; 00523 LNKfieldMapping.Enabled = false; 00524 LBLresult.Text = String.Empty; 00525 TBXreportName.Text = String.Empty; 00526 LNKdownload.Text = String.Empty; 00527 LBXreports.SelectedIndex = -1; 00528 DDLmainMenu.SelectedIndex = 0; 00529 DDLyesNo.Enabled = true; 00530 DDLyesNo.SelectedIndex = 0; 00531 this.DDLmainMenu_SelectedIndexChanged(this, new EventArgs()); 00532 if (DDLquery.Items.Count > 0) 00533 DDLquery.SelectedIndex = 0; 00534 if (DDLsubMenu.Items.Count > 0) 00535 DDLsubMenu.SelectedIndex = 0; 00536 break; 00537 case FormMode.Edit: 00538 LBXreports.Enabled = false; 00539 TBXreportName.Enabled = true; 00540 DDLquery.Enabled = true; 00541 DDLsubMenu.Enabled = true; 00542 DDLmainMenu.Enabled = true; 00543 UPLreportFile.Enabled = true; 00544 BTNadd.Enabled = false; 00545 BTNedit.Enabled = false; 00546 BTNdelete.Enabled = false; 00547 BTNundo.Enabled = true; 00548 BTNapply.Enabled = true; 00549 LNKfieldMapping.Enabled = false; 00550 DDLyesNo.Enabled = true; 00551 LNKdownload.Enabled = true; 00552 break; 00553 case FormMode.Delete: 00554 TBXreportName.Text = String.Empty; 00555 DDLquery.SelectedIndex = 0; 00556 DDLsubMenu.SelectedIndex = 0; 00557 DDLmainMenu.SelectedIndex = 0; 00558 LNKdownload.Text = String.Empty; 00559 LNKfieldMapping.Enabled = false; 00560 BTNdelete.Enabled = false; 00561 BTNedit.Enabled = false; 00562 DDLyesNo.Enabled = false; 00563 LNKdownload.Enabled = false; 00564 DDLyesNo.SelectedIndex = 0; 00565 break; 00566 case FormMode.View: 00567 if (LBXreports.SelectedItem != null) 00568 { 00569 BTNedit.Enabled = true; 00570 BTNdelete.Enabled = true; 00571 LNKfieldMapping.Enabled = true; 00572 Session["SelectedSpecificReportID"] = SelectedSpecificReportID; 00573 } 00574 else 00575 { 00576 BTNedit.Enabled = false; 00577 BTNdelete.Enabled = false; 00578 LNKfieldMapping.Enabled = false; 00579 } 00580 LBXreports.Enabled = true; 00581 TBXreportName.Enabled = false; 00582 DDLquery.Enabled = false; 00583 DDLsubMenu.Enabled = false; 00584 DDLmainMenu.Enabled = false; 00585 UPLreportFile.Enabled = false; 00586 BTNadd.Enabled = true; 00587 BTNundo.Enabled = false; 00588 BTNapply.Enabled = false; 00589 LBLresult.Text = String.Empty; 00590 TBXreportName.Text = String.Empty; 00591 DDLyesNo.Enabled = false; 00592 LNKdownload.Enabled = false; 00593 if (LBXreports.SelectedItem != null) 00594 { 00595 SpecificReportManagement.InitControlsBySpecificReportID(SelectedSpecificReportID, TBXreportName, DDLquery, DDLmainMenu, DDLsubMenu, LNKdownload, DDLyesNo); 00596 } 00597 break; 00598 default: 00599 break; 00600 } 00601 } 00602 #endregion 00603 } 00604 }